# -*- coding:utf-8 -*-


import sys
from common.import_pyside import *


class DemoDialog(QWidget):
    def __init__(self, parent=None):
        super(DemoDialog, self).__init__(parent)

        # 设置窗口标题
        self.setWindowTitle('实战PySide6: QDialog Demo!')
        # 设置窗口大小
        self.resize(400, 320)

        self.initUi()

    def initUi(self):
        # 创建一个垂直布局
        vLayout = QVBoxLayout(self)
        # 设置内部控件之间的间隔

        btnModal = QPushButton('模态对话框测试', self)
        btnModal.clicked.connect(self.onModalDialog)

        btnNormal = QPushButton('常规对话框测试', self)
        btnNormal.clicked.connect(self.onNormalDialog)

        btnMixed = QPushButton('混合对话框测试', self)
        btnMixed.clicked.connect(self.onMixedDialog)

        hLayout = QHBoxLayout(self)
        hLayout.addWidget(btnModal)
        hLayout.addWidget(btnNormal)
        hLayout.addWidget(btnMixed)

        vLayout.addLayout(hLayout)
        vLayout.addWidget(QPlainTextEdit(self))

        self.setLayout(vLayout)

    def onModalDialog(self):
        dlg = QDialog(self)
        dlg.setWindowTitle('模态对话框')
        dlg.resize(240, 136)
        dlg.exec()

    def onNormalDialog(self):
        dlg = QDialog(self)
        dlg.setWindowTitle('常规对话框')
        dlg.resize(240, 136)
        # 设置该属性即可在让在该窗口关闭时就可以释放
        dlg.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
        dlg.show()

    def onMixedDialog(self):
        dlg = QDialog(self)
        dlg.setWindowTitle('混合对话框')
        dlg.resize(240, 136)
        dlg.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
        # 设置非模态对话框的行为类似模态对话框
        dlg.setModal(True)
        dlg.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = DemoDialog()
    window.show()
    sys.exit(app.exec())


